package com.hxd.mall.module.product

import com.hxd.mall.constant.HxdConstants
import com.hxd.mall.constant.HxdGlobalInfo.instance
import com.hxd.mall.module.product.home.bean.ProductUrlBean
import com.hxd.mall.module.product.home.bean.ShareProductBean
import com.hxd.mall.network.base.BaseRequest
import com.hxd.mall.network.service.ManagerFunctionApi
import com.hxd.mall.utils.open.ToastUtil
import com.hxd.mall.utils.open.showDetailShareDialog
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject

/**
 * @author zhaoyong
 * @description:
 * @date :2019/7/17 11:08 AM
 */
class ProductDetailPresenter @Inject constructor(var mView: IProductDetailView) : IProductDetailPresenter {
    override fun fetchProductImage(skuNo: String, channel: String?) {
        BaseRequest.request(
            ManagerFunctionApi.mIConfigureFunctionApi.fetchProductPic(skuNo, channel), mView, {
                mView.fetchProductImageList(it)
            }, {
                ToastUtil.showToast(it.msg.toString())
            })

    }

    override fun getData(isRefresh: Boolean) {
    }

    override fun getDetailData(skuNo: String, channel: String?) {
        BaseRequest.request(
            ManagerFunctionApi.mIConfigureFunctionApi.getProductDetail(skuNo, channel), mView, {
                mView.showData(it)
            }, {
                ToastUtil.showToast(it.msg.toString())
            })
    }

    //获取微信分享的数据
    override fun getVersionInfo(skuNo: String, channel: String?) {
        var bean = ShareProductBean()
        BaseRequest.request(
            ManagerFunctionApi.mIConfigureFunctionApi.getProductShare(skuNo, channel), mView, {
                bean = it
                mView.showSharebean(it)
            }, {
                bean.code = it?.code
                bean.msg = it?.msg
                mView.showSharebean(bean)
            })
    }

    /**
     * 商品购买
     */
    override fun buyProduct(skuNo: String, channel: String?) {
        var bean = ProductUrlBean()
        BaseRequest.request(
            ManagerFunctionApi.mIConfigureFunctionApi.buyProduct(skuNo, channel),mView, {
                bean = it
                mView.getProductUrl(it)
            }, {
                bean.code = it?.code
                bean.msg = it?.msg
                mView.getProductUrl(bean)
            })

    }
}